<!DOCTYPE html>
<html lang="en">
<title>教练课时费列表：${coach.nickName}教练</title>
<#import "/layout/layout.html" as body/>
<@body.page>
<style>
    .dataTables_empty {
        display: none
    }
</style>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title overflow">
                    <h5 class="pull-left">课时费列表：${coach.nickName}教练</h5>
                    <a href="coachCourseFeeEdit.html?coachId=${coach.id}" class="btn btn-sm btn-primary pull-right">编辑课时费</a>

                    <div class="ibox-content">

                        <div class="table-responsive">
                            <form class="form-inline" role="form">
                                <input type="hidden" id="coachId" value="${coach.id}">
                                <div class="form-group">
                                    <label for="year">年份：</label>
                                    <select class="form-control" id="year" name="year">
                                        <option value="">全部</option>
                                        <option value="2016">2016</option>
                                        <option value="2017">2017</option>
                                        <option value="2018">2018</option>
                                        <option value="2019">2019</option>
                                        <option value="2019">2019</option>
                                        <option value="2020">2020</option>
                                        <option value="2021">2021</option>
                                        <option value="2022">2022</option>
                                        <option value="2023">2023</option>
                                        <option value="2024">2024</option>
                                        <option value="2025">2025</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="month">月份：</label>
                                    <select class="form-control" id="month" name="month">
                                        <option value="">全部</option>
                                        <option value="1">1月</option>
                                        <option value="2">2月</option>
                                        <option value="3">3月</option>
                                        <option value="4">4月</option>
                                        <option value="5">5月</option>
                                        <option value="6">6月</option>
                                        <option value="7">7月</option>
                                        <option value="8">8月</option>
                                        <option value="9">9月</option>
                                        <option value="10">10月</option>
                                        <option value="11">11月</option>
                                        <option value="12">12月</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-outline btn-primary" style="margin-top: 5px" onClick="coachPage(1)">确认</button>
                            </form>
                            <hr>
                            <table class="table table-hover table-center dataTables-example">
                                <thead>
                                <tr>
                                    <th>月份</th>
                                    <th>团课课时|课时费</th>
                                    <th>私教销课|课时费</th>
                                    <th>檬营销课|课时费</th>
                                    <th>补充课时费|扣费</th>
                                    <th>课时费合计</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="coachList">
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="ibox-footer overflow">
                        <h4 class="pull-left">合计：¥<span id="coachCount">0</span></h4>
                        <div id="copot-page" class="pull-right"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-loading"></div>
</div>
<script>

    $(document).ready(function () {

        coachPage(1);

        $(document).keypress(function (e) {
            // 回车键事件
            if (e.which === 13) {
                coachPage(1);
            }
        });
    });

    //分页方法
    function coachPage(currentIndex) {
        var param = {
            pageIndex: currentIndex,
            pageSize: 10,
            year: $("#year").val(),
            month: $("#month").val(),
            coachId: $("#coachId").val()
        };
        var $modal_loading = $('.modal-loading');
        $modal_loading.show();
        $("#coachList").empty();
        $.post(
            "${baseUrl}system/coach/coachCourseFeePage",
            param,
            function (result) {
                console.log(result.list);
                var html = "";
                //分页
                new Page({
                    parent: $("#copot-page"),
                    nowPage: currentIndex,
                    pageSize: 10,
                    totalCount: result.count,
                    setting: {
                        defaultPage: 5,//默认显示可点击分页的个数
                        firstPageText: "首页",
                        prevPageText: "上一页",
                        nextPageText: "下一页",
                        lastPageText: "尾页"
                    },
                    callback: function (nowPage, totalPage) {
                        coachPage(nowPage);
                    }
                });

                $("#coachCount").text(result.totalTotalSum);

                var month = null;
                $.each(result.list, function (i, data) {
                    debugger;
                    if (data.month && data.month.toString().length === 1) {
                        month = "0" + data.month;
                    } else {
                        month = data.month;
                    }

                    html += "<tr><td>" + data.year + "-" + month + "</td>";
                    html += "<td>" + data.teamCourseCount + "节 | ¥" + data.teamCourseFeeSum + "</td>";
                    html += "<td>" + data.privateCourseCount + "节 | ¥" + data.privateCourseFeeSum + "</td>";
                    html += "<td>" + data.campCourseCount + "节 | ¥" + data.campCourseFeeSum + "</td>";
                    html += "<td>¥" + data.adjustSupplementFee + "| ¥" + data.adjustReduceFee + "</td>";
                    html += "<td>¥" + data.totalSum + "</td>";
                    html += "<td width='250'>";
                    html += "<button type='button' onclick=' course_fee_detail(" + ${coach.id} +"," + data.year + "," + month + ")' class='btn btn-default'><i class='fa fa-folder'></i> 明细</button>";
                    html += "<button type='button' onclick=' course_fee_adjust(" + ${coach.id} +"," + data.year + "," + month + ")' class='btn btn-default'><i class='fa fa-folder'></i> 补充费用/扣费</button>";
                    html += "</td>";
                    html += "</tr>";
                });
                var _html = result.list.length > 0 ? html : '<tr><td colspan="7" class="text-center" style="padding-top: 50px">暂无数据</td></tr>';
                $("#coachList").html(_html);
                $modal_loading.hide();
            }
        );
    }

    //课时费明细
    function course_fee_detail(id, year, month) {
        debugger;
        window.location = "class_fee_details?id=" + id + "&year=" + year + "&month=" + month;
    }

    //课时费用调整
    function course_fee_adjust(id, year, month) {
        window.location = "coach_course_adjust_fee?coachId=" + id + "&year=" + year + "&month=" + month;
    }

</script>

</@body.page>
</html>